﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ClockMultiHide
{
    public partial class frmClocks : Form
    {
        private int MONITOR_WIDTH = 0;

        public frmClocks()
        {
            InitializeComponent();

            if (!isWinVistaOrBetter()) { this.Opacity = 100; }

            foreach (Screen s in Screen.AllScreens)
            {
                MONITOR_WIDTH += s.WorkingArea.Width;
            }

        }

        private bool isWinVistaOrBetter()
        {
            OperatingSystem os = Environment.OSVersion;
            Version vs = os.Version;
            if ((os.Platform == PlatformID.Win32NT) && (vs.Major >= 6))
            {
                return true; //is Win Vista, Win7, or better
            }
            else
            {
                return false;
            }
        }
        void tpanel_MouseLeave(object sender, EventArgs e)
        {
            _hide();
        }

        void tpanel_MouseEnter(object sender, EventArgs e)
        {
            _show();
        }

        private void _hide()
        {
            
            this.Left = MONITOR_WIDTH - 2;
            this.Top = 4;
        }
        private void _show()
        {
            this.Left = MONITOR_WIDTH - this.Width + 1;
            this.Top = 4; 
        }
        private void transparentPanel1_Click(object sender, EventArgs e)
        {
            _hide();
        }
        
        private void transparentPanel1_MouseEnter(object sender, EventArgs e)
        {
            _show();
        }

        private void transparentPanel1_MouseLeave(object sender, EventArgs e)
        {
            _hide();
        }

        private void transparentPanel1_DoubleClick(object sender, EventArgs e)
        {
            DialogResult r = MessageBox.Show("Exit clock?  Are you sure?","Clock",MessageBoxButtons.YesNo);
            if (r == DialogResult.Yes) { Application.Exit(); }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //per http://msdn.microsoft.com/en-us/library/bb384272.aspx
            //only use time zones that are valid on WinXP and Win7

            TimeZoneInfo hawaii   = TimeZoneInfo.FindSystemTimeZoneById("Hawaiian Standard Time");
            TimeZoneInfo pacific  = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            TimeZoneInfo mountain = TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
            TimeZoneInfo central  = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
            TimeZoneInfo eastern  = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");

            DateTime now = DateTime.UtcNow;

            analogClock2.Time = TimeZoneInfo.ConvertTimeFromUtc(now, hawaii);
            analogClock1.Time = TimeZoneInfo.ConvertTimeFromUtc(now, pacific);
            analogClock3.Time = TimeZoneInfo.ConvertTimeFromUtc(now, mountain);
            analogClock4.Time = TimeZoneInfo.ConvertTimeFromUtc(now, central);
            analogClock5.Time = TimeZoneInfo.ConvertTimeFromUtc(now, eastern);
            
            /*
            analogClock2.Time = DateTime.Now.AddHours(-3); //Hawaii
            analogClock1.Time = DateTime.Now.AddHours(0); //Pacific
            analogClock3.Time = DateTime.Now.AddHours(1); //Mountain
            analogClock4.Time = DateTime.Now.AddHours(2); //Central
            analogClock5.Time = DateTime.Now.AddHours(3); //Eastern
             */

            
        }

        private void frmClocks_Shown(object sender, EventArgs e)
        {
            _hide();
        }
    }
}
